<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/hexo/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/hexo/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/hexo/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/hexo/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/hexo/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/hexo/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/hexo/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="开发笔记,">










<meta name="description" content="好了，昨天聊了半天感想，今天该来聊聊正事儿了，第一次全程从头到尾参与小程序开发的每一步流程，采坑不断，也获益匪浅，有一点总结，分享给大家。开发之前，1.规划明白，自己想要在小程序上做什么事儿，需要用到那些微信提供的接口，这些接口需要什么条件才可以获得，这点至关重要，提前阅读小程序的开发文档十分重要！但是相信大多数人都和我一样，耐不下心来仔细阅读微信的文档，而且他们的文档也不想接口文档一样那么通俗易">
<meta name="keywords" content="开发笔记">
<meta property="og:type" content="article">
<meta property="og:title" content="分享一次小程序开发中的各种坑。。。（续）">
<meta property="og:url" content="https://tony_df.coding.net/2019/07/10/分享一次小程序开发中的各种坑。。。（续）/index.html">
<meta property="og:site_name" content="Tony&#39;s blog">
<meta property="og:description" content="好了，昨天聊了半天感想，今天该来聊聊正事儿了，第一次全程从头到尾参与小程序开发的每一步流程，采坑不断，也获益匪浅，有一点总结，分享给大家。开发之前，1.规划明白，自己想要在小程序上做什么事儿，需要用到那些微信提供的接口，这些接口需要什么条件才可以获得，这点至关重要，提前阅读小程序的开发文档十分重要！但是相信大多数人都和我一样，耐不下心来仔细阅读微信的文档，而且他们的文档也不想接口文档一样那么通俗易">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://tony_df.coding.net/2019/07/10/分享一次小程序开发中的各种坑。。。（续）/%E6%B5%81%E7%A8%8B1.png">
<meta property="og:image" content="https://tony_df.coding.net/2019/07/10/分享一次小程序开发中的各种坑。。。（续）/%E6%B5%81%E7%A8%8B2.png">
<meta property="og:image" content="https://tony_df.coding.net/2019/07/10/分享一次小程序开发中的各种坑。。。（续）/ssl1.png">
<meta property="og:image" content="https://tony_df.coding.net/2019/07/10/分享一次小程序开发中的各种坑。。。（续）/ssl2.png">
<meta property="og:image" content="https://tony_df.coding.net/2019/07/10/分享一次小程序开发中的各种坑。。。（续）/ssl3.png">
<meta property="og:image" content="https://tony_df.coding.net/2019/07/10/分享一次小程序开发中的各种坑。。。（续）/ssl4.png">
<meta property="og:image" content="https://tony_df.coding.net/2019/07/10/分享一次小程序开发中的各种坑。。。（续）/ssl5.png">
<meta property="og:image" content="https://tony_df.coding.net/2019/07/10/分享一次小程序开发中的各种坑。。。（续）/ssl6.png">
<meta property="og:image" content="https://tony_df.coding.net/2019/07/10/分享一次小程序开发中的各种坑。。。（续）/ssl7.png">
<meta property="og:image" content="https://tony_df.coding.net/2019/07/10/分享一次小程序开发中的各种坑。。。（续）/ssl8.png">
<meta property="og:updated_time" content="2019-07-10T03:09:03.668Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="分享一次小程序开发中的各种坑。。。（续）">
<meta name="twitter:description" content="好了，昨天聊了半天感想，今天该来聊聊正事儿了，第一次全程从头到尾参与小程序开发的每一步流程，采坑不断，也获益匪浅，有一点总结，分享给大家。开发之前，1.规划明白，自己想要在小程序上做什么事儿，需要用到那些微信提供的接口，这些接口需要什么条件才可以获得，这点至关重要，提前阅读小程序的开发文档十分重要！但是相信大多数人都和我一样，耐不下心来仔细阅读微信的文档，而且他们的文档也不想接口文档一样那么通俗易">
<meta name="twitter:image" content="https://tony_df.coding.net/2019/07/10/分享一次小程序开发中的各种坑。。。（续）/%E6%B5%81%E7%A8%8B1.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/hexo/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Tony'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://tony_df.coding.net/2019/07/10/分享一次小程序开发中的各种坑。。。（续）/">





  <title>分享一次小程序开发中的各种坑。。。（续） | Tony's blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/hexo/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Tony's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">学着码代码,学着码人生;</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/hexo/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br>
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/hexo/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br>
            
            Tags
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/hexo/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br>
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://tony_df.coding.net/hexo/2019/07/10/分享一次小程序开发中的各种坑。。。（续）/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Tony">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/hexo/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Tony's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">分享一次小程序开发中的各种坑。。。（续）</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-07-10T08:58:15+08:00">
                2019-07-10
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>好了，昨天聊了半天感想，今天该来聊聊正事儿了，第一次全程从头到尾参与小程序开发的每一步流程，采坑不断，也获益匪浅，有一点总结，分享给大家。<br>开发之前，<br>1.规划明白，自己想要在小程序上做什么事儿，需要用到那些微信提供的接口，这些接口需要什么条件才可以获得，这点至关重要，提前阅读小程序的开发文档十分重要！但是相信大多数人都和我一样，耐不下心来仔细阅读微信的文档，而且他们的文档也不想接口文档一样那么通俗易懂，所以，如果周围有做过小程序的人，提前请教，如果没有，到微信小程序的开发社区上<a href="https://developers.weixin.qq.com/community/develop/mixflow" target="_blank" rel="noopener">https://developers.weixin.qq.com/community/develop/mixflow</a>逛一下，搜一下想问的问题，上面采过坑的人多的是，总有一个坑适合你~~<br>2.根据1的结果，准备好注册小程序的资质文件，涉及到的关键权限包括支付，人脸核身等，根据需要，选择合适的服务类目，并填写好小程序的基本信息，有条件的话，最好也完成微信认证（300元）。<br><img src="%E6%B5%81%E7%A8%8B1.png" alt="流程1"><br>3.准备好小程序的接口域名和ssl证书。<br>4.在小程序控制台，配置好request域名，业务域名等关键配置，设置好体验成员。<br><img src="%E6%B5%81%E7%A8%8B2.png" alt="流程2"><br>至此，开发前的准备工作就基本完成了。<br>简单介绍下ssl证书的申请流程，按说域名和证书的配置都应该有对应的管理人员来完成，但由于我们的项目是公司第一个完全前后端分离的项目，也是少数需要部署ssl证书的项目，所以这个申请流程也是我们自己来完成的，对于小程序来说，有一个免费的证书就足够了，当然这个也是看业务需要，如果你们公司需要扩展业务，需要适配通配符域名，安全性更高，兼容性更好的证书，那就得花点银子了。<br>这里我就说一下免费证书的申请流程。<br>目前，阿里，百度，腾讯等各大平台都有提供申请免费证书的入口，但有一定的限制条件，就是你的服务器地址最好也是他们的，申请和配置的过程会非常简单，我们的情况不一样，所以我的ssl证书没有在他们的平台申请，而是在freessl<a href="https://freessl.cn/" target="_blank" rel="noopener">https://freessl.cn/</a>上申请的，这也是一个在开发者领域享誉盛名的证书签发地址，没有诸多限制，口碑极佳，推荐各位如果需要免费的ssl证书，到此一游。<br>首先，输入你要申请证书的域名<br><img src="ssl1.png" alt="ssl1"><br>然后，选择证书类型（一般情况默认就好），输入邮箱地址，<br><img src="ssl2.png" alt="ssl2"><br>点击创建后，会提示你下载keymanager客户端，如果没有下载过，就下载一下，然后刷新页面，下载后直接打开，<br><img src="ssl3.png" alt="ssl3"><br>接着会在keymanager客户端完成证书的生成<br><img src="ssl4.png" alt="ssl4"><br>然后返回浏览器，进行dns验证解析，<br><img src="ssl5.png" alt="ssl5"><br>这里需要将证书生成的txt类型记录值，拿到域名申请的地方，去填写下域名的txt记录值，这里因为我之前已经配置好了，这一步就不演示了，<br>需要大家打开域名申请的网站，填写freessl生成的txt记录值，然后点击dns验证，即可验证通过。<br>之后回到keymanager，即可在全部证书的列表里，看到刚刚颁发的合法证书<br><img src="ssl6.png" alt="ssl6"><br>然后就是将证书导出，到服务器上配置一下就OK了<br><img src="ssl7.png" alt="ssl7"><br>我们需要的是nginx类型的，需要说明一下，如果你需要导出的是iis类型的证书，那么需要配置证书私钥，其他类型不需要，可有可无。<br><img src="ssl8.png" alt="ssl8"><br>在服务器上导入证书的流程我就不说了，nginx的证书导入还是比较简单的，本身nginx的配置文件也没多少行，大致流程是将证书放在nginx根目录下，最好是新建一个文件夹，然后把证书路径配置到nginx配置文件中，重启就可以了，如果你的网站用了反向代理，那么证书需要导入到反向代理服务器，类似的教程多的是，不再多说。<br>至此，我们的准备工作完成。<br>开始开发<br>进入开发阶段，其实就看各自需求了，我们的业务需求比较简单，前一篇提过我们的审核未通过，因为主体不符合要求，涉及了人脸识别，所以未能顺利通过，但我想说的是，很多事情就是这样，结果可能并不尽人意，但过程需要足够精彩，在过程中学习成长，可能这次结果不好，但有了这样的经验，下次就不会在同一个地方栽跟头，不能因为怕出错，就不敢尝试。<br>好了，说一下我们遇到的需求，大概列表如下<br>1.通过人脸识别+定位完成学生的自助签到<br>2.通过1的结果，完成绑定学生的微信绑定，可以通过微信登录系统，完成相关操作<br>3.在小程序内使用web-view,快捷访问之前做好的手机站<br>大概的需求就是这样，来看一下实现<br>首先，人脸识别我们用的是百度的接口，简单聊一下人脸识别，这个属于AI的范畴，目前国内在人脸识别做的好的有，B.A.T，旷视(face++)，虹软等几家企业，可以说各有所长，论坛上说，旷视在这方面是做的最好的（我想也是，因为就他收费高，支付宝和好多手机品牌的人脸识别技术就是旷视的…），但从成本来看，百度是最合适的，只要完成了企业认证，就可以获得10QPS的配额也是非常厚道了，而且百度也提供离线sdk，只是对计算能力有一定的要求，而且百度的技术也是值得信赖的（众所周知百度是国内技术信仰值最高的企业），所以我们选择了百度；<br>这里我分享一下，根据百度提供借接口API来封装人脸识别接口的过程，不建议直接使用它的sdk，因为sdk的封装标准是要求最低依赖，最高兼容，但调用百度接口的时候需要有一个token，这个值其实是有30天有效期的，但由于sdk有封装标准，他就不能设置token的有效期，只能每次调用前都获取一次token来规避token过期的问题，也就造成了一些资源的浪费，所以，建议大家根据api文档<a href="http://ai.baidu.com/docs#/Face-Guide/top" target="_blank" rel="noopener">http://ai.baidu.com/docs#/Face-Guide/top</a>，自己封装符合自己项目的sdk，自己封装就可以有一些依赖，比如我们可以引入redis来缓存token，这样就能提高效率，来看一下代码</p>
<figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;summary&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> 通过接口获取token，并缓存到redis</span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;/summary&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;returns&gt;</span><span class="doctag">&lt;/returns&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">string</span> <span class="title">getAccessToken</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    RedisExchange redis = <span class="keyword">new</span> RedisExchange();</span><br><span class="line">    <span class="keyword">string</span> clientId = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings[<span class="string">"BD_AI_AppKey"</span>]);</span><br><span class="line">    <span class="keyword">string</span> clientSecret = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings[<span class="string">"BD_AI_Secret"</span>]);</span><br><span class="line">    <span class="keyword">string</span> token = redis.StringGet(<span class="string">"bd_ai_token"</span>);</span><br><span class="line">    <span class="keyword">string</span> result = <span class="string">""</span>;</span><br><span class="line">    <span class="keyword">if</span> (!<span class="keyword">string</span>.IsNullOrEmpty(token))</span><br><span class="line">    &#123;</span><br><span class="line">        result = token;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">string</span> authHost = <span class="string">"https://aip.baidubce.com/oauth/2.0/token"</span>;</span><br><span class="line">        HttpClient client = <span class="keyword">new</span> HttpClient();</span><br><span class="line">        List&lt;KeyValuePair&lt;<span class="keyword">string</span>, <span class="keyword">string</span>&gt;&gt; paraList = <span class="keyword">new</span> List&lt;KeyValuePair&lt;<span class="keyword">string</span>, <span class="keyword">string</span>&gt;&gt;(<span class="number">3</span>);</span><br><span class="line">        paraList.Add(<span class="keyword">new</span> KeyValuePair&lt;<span class="keyword">string</span>, <span class="keyword">string</span>&gt;(<span class="string">"grant_type"</span>, <span class="string">"client_credentials"</span>));</span><br><span class="line">        paraList.Add(<span class="keyword">new</span> KeyValuePair&lt;<span class="keyword">string</span>, <span class="keyword">string</span>&gt;(<span class="string">"client_id"</span>, clientId));</span><br><span class="line">        paraList.Add(<span class="keyword">new</span> KeyValuePair&lt;<span class="keyword">string</span>, <span class="keyword">string</span>&gt;(<span class="string">"client_secret"</span>, clientSecret));</span><br><span class="line">        HttpResponseMessage response = client.PostAsync(authHost, <span class="keyword">new</span> FormUrlEncodedContent(paraList)).Result;</span><br><span class="line">        result = response.Content.ReadAsStringAsync().Result;</span><br><span class="line">        BdAIAuthModel model = JsonHelper.JSONToObject&lt;BdAIAuthModel&gt;(result);</span><br><span class="line">        redis.StringSet(<span class="string">"bd_ai_token"</span>, model.access_token, DateTime.Now.AddDays(<span class="number">1</span>) - DateTime.Now);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> result;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>然后将接口返回值封装成类</p>
<figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">BdAIFaceSearchModel</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;summary&gt;</span></span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> 图片信息(总数据大小应小于10M)，图片上传方式根据image_type来判断</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;/summary&gt;</span></span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">string</span> image &#123; <span class="keyword">get</span>; <span class="keyword">set</span>; &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;summary&gt;</span></span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> 图片类型</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> BASE64:图片的base64值，base64编码后的图片数据，编码后的图片大小不超过2M；</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> URL:图片的 URL地址(可能由于网络等原因导致下载图片时间过长)；</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> FACE_TOKEN: 人脸图片的唯一标识，调用人脸检测接口时，会为每个人脸图片赋予一个唯一的FACE_TOKEN，同一张图片多次检测得到的FACE_TOKEN是同一个。</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;/summary&gt;</span></span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">string</span> image_type &#123; <span class="keyword">get</span>; <span class="keyword">set</span>; &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;summary&gt;</span></span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> 从指定的group中进行查找 用逗号分隔，上限10个</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;/summary&gt;</span></span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">string</span> group_id_list &#123; <span class="keyword">get</span>; <span class="keyword">set</span>; &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;summary&gt;</span></span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> 图片质量控制</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> NONE: 不进行控制</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> LOW:较低的质量要求</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> NORMAL: 一般的质量要求</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> HIGH: 较高的质量要求</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> 默认 NONE</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> 若图片质量不满足要求，则返回结果中会提示质量检测失败</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;/summary&gt;</span></span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">string</span> quality_control &#123; <span class="keyword">get</span>; <span class="keyword">set</span>; &#125; = <span class="string">"NORMAL"</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;summary&gt;</span></span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> 活体控制 检测结果中不符合要求的人脸会被过滤</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> NONE: 不进行控制</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> LOW:较低的活体要求(高通过率 低攻击拒绝率)</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> NORMAL: 一般的活体要求(平衡的攻击拒绝率, 通过率)</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> HIGH: 较高的活体要求(高攻击拒绝率 低通过率)</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> 默认NONE</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;/summary&gt;</span></span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">string</span> liveness_control &#123; <span class="keyword">get</span>; <span class="keyword">set</span>; &#125; = <span class="string">"NONE"</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;summary&gt;</span></span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> 当需要对特定用户进行比对时，指定user_id进行比对。即人脸认证功能。</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;/summary&gt;</span></span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">string</span> user_id &#123; <span class="keyword">get</span>; <span class="keyword">set</span>; &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;summary&gt;</span></span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> 查找后返回的用户数量。返回相似度最高的几个用户，默认为1，最多返回50个。</span></span><br><span class="line">    <span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;/summary&gt;</span></span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">int</span> max_user_num &#123; <span class="keyword">get</span>; <span class="keyword">set</span>; &#125; = <span class="number">1</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>然后可以实现1：N搜索的具体方法，httppost是网络请求方法，JsonHelper是解析对象和json字符串的帮助类</p>
<figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;summary&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> 1:N，人脸搜索</span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;/summary&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;param name="_params"&gt;</span><span class="doctag">&lt;/param&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;returns&gt;</span><span class="doctag">&lt;/returns&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">string</span> <span class="title">faceSearch</span>(<span class="params">BdAIFaceSearchModel _params</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">string</span> token = getAccessToken();</span><br><span class="line">    <span class="keyword">string</span> host = <span class="string">"https://aip.baidubce.com/rest/2.0/face/v3/search?access_token="</span> + token;</span><br><span class="line">    <span class="keyword">string</span> str = JsonHelper.ObjectToJSON(_params);</span><br><span class="line">    <span class="keyword">return</span> httpPost(host, str);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>接着就可以在写接口调用了</p>
<figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;summary&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> 人脸搜索1:N</span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;/summary&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;param name="model"&gt;</span><span class="doctag">&lt;/param&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;returns&gt;</span><span class="doctag">&lt;/returns&gt;</span></span></span><br><span class="line">[<span class="meta">HttpPost</span>]</span><br><span class="line"><span class="function"><span class="keyword">public</span> Response <span class="title">SearchFace</span>(<span class="params">BdAIFaceSearchModel model</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    Response resp = <span class="keyword">new</span> Response();</span><br><span class="line">    <span class="keyword">try</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">string</span> ret = BdAIHelper.faceSearch(model);</span><br><span class="line">        BdAISearchReturnModel retmsg = JsonHelper.JSONToObject&lt;BdAISearchReturnModel&gt;(ret);</span><br><span class="line">        <span class="keyword">if</span> (retmsg.error_code == <span class="number">0</span>)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">double</span> score = Convert.ToDouble(retmsg.result.user_list[<span class="number">0</span>].score);</span><br><span class="line">            <span class="keyword">if</span> (score &gt; <span class="number">75</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                resp.code = <span class="number">1</span>;</span><br><span class="line">                resp.message = <span class="string">"success"</span>;</span><br><span class="line">                resp.data = <span class="keyword">new</span> &#123; ret = retmsg.result &#125;;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span></span><br><span class="line">            &#123;</span><br><span class="line">                resp.code = <span class="number">4010</span>;</span><br><span class="line">                resp.message = <span class="string">"未找到对应人脸"</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">        &#123;</span><br><span class="line">            resp.code = <span class="number">0</span>;</span><br><span class="line">            resp.message = <span class="string">"error"</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">catch</span>(Exception ex)</span><br><span class="line">    &#123;</span><br><span class="line">        resp.code = <span class="number">-1</span>;</span><br><span class="line">        resp.message = <span class="string">"error:"</span>+ ex.Message;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> resp;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>这里我只介绍了1：N搜索的封装调用过程，其他接口类似，可以看到，我在接口里只是简单的逻辑判断，没有写很多复杂的逻辑，这符合restful接口的编写原则，逻辑清晰简单，别人看的时候，不会因为代码的晦涩而感到迷茫，可以很快接手并扩展，这才是接口的正确打开方式（好像是在自夸…），其实不管是做什么项目，都不应该把代码写的长篇大论或者晦涩难懂，如遇特殊情况也要加以注释说明，这既是对自己负责，也是对团队负责。<br>此外我们的项目还涉及小程序的消息推送，以及手机号码的解析，这个都属于那种有固定写法的，只要遵照微信开发文档的要求，都不是什么难事，分享下我们的写法，仅供参考</p>
<figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;summary&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> 微信推送服务消息，采用异步方法</span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;/summary&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;param name="guid"&gt;</span><span class="doctag">&lt;/param&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;param name="url"&gt;</span><span class="doctag">&lt;/param&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;param name="openid"&gt;</span><span class="doctag">&lt;/param&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;param name="msg"&gt;</span><span class="doctag">&lt;/param&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;param name="username"&gt;</span><span class="doctag">&lt;/param&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;param name="token"&gt;</span><span class="doctag">&lt;/param&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;returns&gt;</span><span class="doctag">&lt;/returns&gt;</span></span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">async</span> System.Threading.Tasks.<span class="function">Task&lt;<span class="keyword">bool</span>&gt; <span class="title">PushMessageAsync</span>(<span class="params"><span class="keyword">string</span> userid, <span class="keyword">string</span> openid, <span class="keyword">string</span> username, <span class="keyword">string</span> camp_name, <span class="keyword">string</span> time, <span class="keyword">string</span> number</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">string</span> accessToken = GetWxAccessToken();</span><br><span class="line">    <span class="keyword">string</span> url = <span class="string">"https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token="</span> + accessToken;</span><br><span class="line">    RedisExchange redis = <span class="keyword">new</span> RedisExchange();</span><br><span class="line">    <span class="keyword">string</span> form_id = redis.StringGet(userid + <span class="string">"|form_id"</span>);</span><br><span class="line">    StringBuilder sbparams = <span class="keyword">new</span> StringBuilder();</span><br><span class="line">    sbparams.Append(<span class="string">"&#123;"</span>);</span><br><span class="line">    sbparams.Append(<span class="string">"\"touser\": \""</span> + openid + <span class="string">"\""</span>);</span><br><span class="line">    sbparams.Append(<span class="string">",\"template_id\": \"你的模板id\""</span>);</span><br><span class="line">    sbparams.Append(<span class="string">",\"page\": \"要跳转的页面\""</span>);</span><br><span class="line">    sbparams.Append(<span class="string">",\"form_id\": \""</span> + form_id + <span class="string">"\""</span>);</span><br><span class="line">    sbparams.Append(<span class="string">",\"data\": &#123;"</span>);</span><br><span class="line">    sbparams.Append(<span class="string">"\"keyword1\": &#123;\"value\": \""</span> + username + <span class="string">"\"&#125;,"</span>);<span class="comment">//签到人字段</span></span><br><span class="line">    sbparams.Append(<span class="string">"\"keyword2\": &#123;\"value\": \""</span> + time + <span class="string">"\"&#125;,"</span>);<span class="comment">//标注消息内容</span></span><br><span class="line">    sbparams.Append(<span class="string">"\"keyword3\": &#123;\"value\": \""</span> + camp_name + <span class="string">"\"&#125;,"</span>);<span class="comment">//签到分营</span></span><br><span class="line">    sbparams.Append(<span class="string">"\"keyword4\": &#123;\"value\": \""</span> + number + <span class="string">"\"&#125;"</span>);<span class="comment">//签到码</span></span><br><span class="line">    sbparams.Append(<span class="string">"&#125;"</span>);</span><br><span class="line">    sbparams.Append(<span class="string">"&#125;"</span>);</span><br><span class="line">    LogHelper.WriteLog(sbparams.ToString());</span><br><span class="line">    PostMoths(url, sbparams.ToString());</span><br><span class="line">    <span class="keyword">await</span> System.Threading.Tasks.Task.Delay(<span class="number">100</span>);</span><br><span class="line">    redis.KeyDelete(userid + <span class="string">"|form_id"</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>解密微信手机号</p>
<figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;summary&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> 解密小程序数据</span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;/summary&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;param name="encryptedDataStr"&gt;</span>加密数据<span class="doctag">&lt;/param&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;param name="key"&gt;</span>sessionkey<span class="doctag">&lt;/param&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;param name="iv"&gt;</span>解密向量<span class="doctag">&lt;/param&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;returns&gt;</span><span class="doctag">&lt;/returns&gt;</span></span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">string</span> <span class="title">AES_decrypt</span>(<span class="params"><span class="keyword">string</span> encryptedDataStr, <span class="keyword">string</span> key, <span class="keyword">string</span> iv</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    System.Security.Cryptography.RijndaelManaged rijalg = <span class="keyword">new</span> System.Security.Cryptography.RijndaelManaged();</span><br><span class="line">    <span class="comment">//设置 cipher 格式 AES-128-CBC</span></span><br><span class="line">    iv = iv.Replace(<span class="string">" "</span>, <span class="string">"+"</span>);</span><br><span class="line">    key = key.Replace(<span class="string">" "</span>, <span class="string">"+"</span>);</span><br><span class="line">    encryptedDataStr = encryptedDataStr.Replace(<span class="string">" "</span>, <span class="string">"+"</span>);</span><br><span class="line">    rijalg.KeySize = <span class="number">128</span>;</span><br><span class="line"></span><br><span class="line">    rijalg.Padding = System.Security.Cryptography.PaddingMode.PKCS7;</span><br><span class="line">    rijalg.Mode = System.Security.Cryptography.CipherMode.CBC;</span><br><span class="line">    rijalg.Key = Convert.FromBase64String(key);</span><br><span class="line">    rijalg.IV = Convert.FromBase64String(iv);</span><br><span class="line">    <span class="keyword">byte</span>[] encryptedData = Convert.FromBase64String(encryptedDataStr);</span><br><span class="line">    <span class="comment">//解密</span></span><br><span class="line">    System.Security.Cryptography.ICryptoTransform decryptor = rijalg.CreateDecryptor();</span><br><span class="line">    <span class="keyword">byte</span>[] plainText = decryptor.TransformFinalBlock(encryptedData, <span class="number">0</span>, encryptedData.Length);</span><br><span class="line">    <span class="keyword">string</span> result = System.Text.Encoding.UTF8.GetString(plainText);</span><br><span class="line">    <span class="keyword">return</span> result;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;summary&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> 接收微信手机号码的加密数据并解密</span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;/summary&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;param name="wxModel"&gt;</span><span class="doctag">&lt;/param&gt;</span></span></span><br><span class="line"><span class="comment"><span class="doctag">///</span> <span class="doctag">&lt;returns&gt;</span><span class="doctag">&lt;/returns&gt;</span></span></span><br><span class="line">[<span class="meta">HttpPost</span>]</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">async</span> Task&lt;Response&gt; <span class="title">DecryptMobile</span>(<span class="params">[FromBody] WxMobileModel wxModel</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    Response resp = <span class="keyword">new</span> Response();</span><br><span class="line">    <span class="keyword">try</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">string</span> session_key = redisExchange.StringGet(wxModel.open_id + <span class="string">"_sessionkey"</span>);</span><br><span class="line">        <span class="keyword">string</span> str = Lib.UserHelper.AES_decrypt(wxModel.encryptedData.Trim(), session_key, wxModel.iv.Trim());</span><br><span class="line">        <span class="keyword">var</span> ret = JsonHelper.DataRowFromJSON(str);</span><br><span class="line">        <span class="keyword">string</span> mobile = Convert.ToString(ret[<span class="string">"phoneNumber"</span>]);<span class="comment">//phoneNumber:带区号的手机号，purePhoneNumber:不带区号的手机号，由于可能有香港 ，澳门等学生，返回带区号的手机号</span></span><br><span class="line">        WxOauthManager wx_manager = <span class="keyword">new</span> WxOauthManager();</span><br><span class="line">        <span class="keyword">var</span> oauth = wx_manager.Find(u =&gt; u.open_id == wxModel.open_id);</span><br><span class="line">        <span class="keyword">if</span> (oauth != <span class="literal">null</span>)</span><br><span class="line">        &#123;</span><br><span class="line">            oauth.mobile = mobile;</span><br><span class="line">            resp = <span class="keyword">await</span> wx_manager.UpdateAsync(oauth);</span><br><span class="line">            <span class="keyword">if</span> (resp.code == <span class="number">1</span>)</span><br><span class="line">                resp.message = <span class="string">"请和管理人员核对手机号码"</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">        &#123;</span><br><span class="line">            resp.code = <span class="number">4010</span>;</span><br><span class="line">            resp.message = <span class="string">"failed"</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">catch</span> (Exception ex)</span><br><span class="line">    &#123;</span><br><span class="line">        resp.code = <span class="number">-1</span>;</span><br><span class="line">        resp.message = <span class="string">"error:"</span> + ex.Message;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> resp;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>好了，大概的技术要点就是这些，后面两段属于公式类型的，写好了一次，只要微信的开发规则不变，代码也基本不用变，其实开发的流程是比较顺畅的，只要需求搞明白，开始写代码的时候就成竹在胸，就像拼拼图一样，很快就可以完成，所以我之前在博客里反复会说，结题的思路还是最重要的，思路清晰了，代码自然而然就写出来了，这是一个很流畅的过程。<br>好了，这篇就到这。</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/hexo/tags/开发笔记/" rel="tag"># 开发笔记</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/hexo/2019/07/09/分享一次小程序开发中的各种坑。。。/" rel="next" title="分享一次小程序开发中的各种坑。。。">
                <i class="fa fa-chevron-left"></i> 分享一次小程序开发中的各种坑。。。
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/hexo/2019/08/14/聊聊在设计方案定下来后的技术选型/" rel="prev" title="聊聊在设计方案定下来后的技术选型">
                聊聊在设计方案定下来后的技术选型 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
        <!-- Go to www.addthis.com/dashboard to customize your tools -->
<div class="addthis_inline_share_toolbox">
  <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5bbb2338b87602f0" async="async"></script>
</div>

      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zOTA1My8xNTU4MA"></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Tony</p>
              <p class="site-description motion-element" itemprop="description">学习总结</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/hexo/archives/">
              
                  <span class="site-state-item-count">58</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/hexo/tags/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">tags</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Tony</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/hexo/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/hexo/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/hexo/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/hexo/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/hexo/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/hexo/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/hexo/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/hexo/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/hexo/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/hexo/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/hexo/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  












  





  

  

  

  
  

  

  

  

</body>
</html>
